n=eval(input())
year=1970
month=1
day=1
list1=[1,3,5,7,8,10,12]
list2=[4,6,9,11]
if n>=0:
    while n>=365:
        if (year%4==0 and year%100!=0) or (year%400==0):
            n=n-366
        else:
            n=n-365
        year+=1
        if ((year%4==0 and year%100!=0) or (year%400==0)) and n-366<0:
            break
        elif n-365<0:
            break
    while n>=31:
        if month in list1:
            n=n-31
        elif month in list2:
            n=n-30
        elif ((year%4==0 and year%100!=0) or (year%400==0)) and month==2:
            n=n-29
        else:
            n=n-28
        month+=1
        if month in list1 and n-31<0:
            break
        elif month in list2 and n-30<0:
            break
        elif ((year%4==0 and year%100!=0) or (year%400==0)) and month==2 and n-29<0:
            break
        elif n-28<0:
            break
    day=n+1
else:
    n=-n
    if n<365:
        year=1969
    else:
        year=1969
        while True:
            if (year%4==0 and year%100!=0) or (year%400==0):
                n-=366
            else:
                n-=365
            year-=1
            if ((year%4==0 and year%100!=0) or (year%400==0)) and n-366<=0:
                break
            elif n-365<=0:
                break
    year=year
    month=12
    while n>=31:
        if month in list1:
            n=n-31
        elif month in list2:
            n=n-30
        elif ((year%4==0 and year%100!=0) or (year%400==0)) and month==2:
            n=n-29
        else:
            n=n-28
        month-=1
        if month in list1 and n-31<=0:
            break
        elif month in list2 and n-30<=0:
            break
        elif ((year%4==0 and year%100!=0) or (year%400==0)) and month==2 and n-29<=0:
            break
        elif n-28<=0:
            break
    if month in list1:
        day=31-n+1
    elif month in list2:
        day=30-n+1
    elif ((year%4==0 and year%100!=0) or (year%400==0)) and month==2:
        day=29-n+1
    else:
        day=28-n+1
print(year)
print(month)
print(day)
